const path = require('path');
const ip = require('ip')

module.exports = {
	publicPath: './', //配置打包时的相对路径
	filenameHashing: true,
	lintOnSave: false,
	productionSourceMap: false,
	devServer: {
		port: '8081', //代理端口
		open: false, //项目启动时是否自动打开浏览器，我这里设置为false,不打开，true表示打开
		proxy: {
			'/rtsp': {
				target: `http://${ip.address()}:8088`,
				changeOrigin: true,
				ws: true, // proxy websockets
				pathRewrite: {
					'^/rtsp': ''
				}
			},
			'/': {
				// target: 'http://192.168.1.6:8082', //文康
				// target: 'http://192.168.1.50:8080', //燕龙
				target: 'http://192.168.1.19:8089', //鸿飞
        // target: `http://${ip.address()}:8089`, //鸿飞
				// target: 'http://192.168.1.126:8080', //外网ip
				// target: 'http://125.62.24.251:8080', //万盛ip
				changeOrigin: true, //是否跨域
				ws: true, // proxy websockets
				pathRewrite: {
					'^/': ''
				}
			}
		}
	},
	chainWebpack: (config) => {
		config.resolve.alias.set('vue$', 'vue/dist/vue.esm.js').set('services', resolve('src/services'));
		config.module.rule('pug').test(/\.pug$/).use('pug-html-loader').loader('pug-html-loader').end();

		const types = [ 'vue-modules', 'vue', 'normal-modules', 'normal' ];
		types.forEach((type) => addStyleResource(config.module.rule('stylus').oneOf(type)));
	}
};

function resolve(dir) {
	return path.join(__dirname, dir);
}

function addStyleResource(rule) {
	rule.use('style-resource').loader('style-resources-loader').options({
		patterns: [ path.resolve(__dirname, './src/styles/imports.styl') ]
	});
}
